package com.potenza.training.resume.controller;

import com.potenza.training.resume.entity.ResumeHope;
import com.potenza.training.resume.service.ResumeHopeService;
import io.renren.common.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("resume/hope")
public class ResumeHopeController {

    @Autowired
    private ResumeHopeService resumeHopeService;

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("resume:hope:save")
    public R save(@RequestBody ResumeHope resumeHope){
        resumeHopeService.saveResumeHope(resumeHope);

        return R.ok();
    }

    /**
     * 列表
     */
    @RequestMapping("/list/{userId}")
    @RequiresPermissions("resume:hope:list")
    public R list(@PathVariable Integer userId){
        List<ResumeHope> list = resumeHopeService.findAll(userId);

        return R.ok().put("data", list);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("resume:hope:update")
    public R update(@RequestBody ResumeHope resumeHope){
        resumeHopeService.updateResumeHope(resumeHope);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("resume:hope:delete")
    public R delete(@RequestBody Integer[] ids){
        resumeHopeService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }
}
